﻿using System;
using System.Windows.Data;

namespace EpiNEXT.Presentation.Controls.Converters
{
    /// <summary>
    /// Converts zero length into collapsed visibility
    /// </summary>
    public class LengthToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int length;
            bool success = int.TryParse(value.ToString(), out length);

            if (success)
            {
                if (length > 0)
                {
                    return System.Windows.Visibility.Visible;
                }
                else
                {
                    return System.Windows.Visibility.Collapsed;
                }
            }
            

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
